from random import randint

class Player:
	""" Class to hold the state and function of each player on the field.
	"""
	def __init__(self, loc):
		""" constructor takes the initial loc of the player placement
			TODO: should take a facing argument
		"""
		self.name = "Default"
		self.abilities = []		
		
	
		self.facing = None
		self.loc = loc
		self.moves = 50

		# Store the adj spaces for a quick lookup when we don't need up to date into. 
		# Can never be older than last move.
		self.adj = []
		
	def has_moves(self):
		""" Returns true if the player has moves left.
		"""
		if self.moves > 0:
			return True
		else:
			return False
			
	def move_to(self, loc):
		""" Moves the player to the specified loc. This is left as a static 1 cost for movement 
			since moves in bloodbowl are made one step at a time.
		"""
		if self.has_moves():
			self.loc = loc
			self.moves -= 1
		else:
			print 'no moves left'

	def get_adj(self):
		"""	Returns a list of all the adjacent squares to the player.
		"""
		self.adj = []
		#[(self.loc[0] + i, self.loc[0] + j) for i in xrange(-1,2) for j in  xrange(-1,2) if not (i == 0 and j == 0)]                           
		self.adj.append((self.loc[0]+1,self.loc[1]))
		self.adj.append((self.loc[0]-1,self.loc[1]))
		self.adj.append((self.loc[0],self.loc[1]+1))
		self.adj.append((self.loc[0],self.loc[1]-1))
		self.adj.append((self.loc[0]+1,self.loc[1]+1))
		self.adj.append((self.loc[0]-1,self.loc[1]-1))
		self.adj.append((self.loc[0]+1,self.loc[1]-1))
		self.adj.append((self.loc[0]-1,self.loc[1]+1))
		return self.adj
		
	def is_adj(self,loc):
		""" checks if a sqare is adjacent to the player
		"""
		for l in self.get_adj():
			if l == loc:
				return loc

	def get_facing(self):
		""" returns the direction the player is facing for drawing 
		"""
		return self.facing

class Team:
	""" TODO: Not implemented
	"""
	def __init__(self, team_type):
		self.players = []
		self.type = team_type
		
	def make_stock_team(self):
		if self.type == 'home':
			for n in range(9):
				self.players.append(Player( (randint(0,12),randint(0,14))))
		if self.type == 'away':
			for n in range(9):
				self.players.append(Player( (randint(13,25),randint(0,14))))

